"""
Django settings for dmessage project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
from .secret import SECRET_KEY, DATABASE_PASSWORD

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
# SECRET_KEY = ...

# SECURITY WARNING: don't run with debug turned on in production!
import socket
hostname = socket.gethostname()
if 'SERVER' not in hostname :
    #Development Server Settings go here
    DEBUG = True
else:
    #Production Server Settings go here
    DEBUG = False
    ALLOWED_HOSTS = [
       '.hcc.io',   # Allow domain and subdomains
       '.hcc.io.',  # Also allow FQDN and subdomains
    ]


# Application definition

INSTALLED_APPS = (
#    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'chat', 
)

MIDDLEWARE = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'dmessage.urls'

WSGI_APPLICATION = 'dmessage.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

if hostname in ('laptop', 'fedora.local', 'fedora-2.local', 'localhost.localdomain') :
	DATABASES = {
    	'default': {
    	    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    	    'NAME': 'postgres',
    	    'USER': 'postgres',
    	    'PASSWORD': DATABASE_PASSWORD,
    	    'HOST': '127.0.0.1',
    	    'PORT': '5432',
    	}
	}
else :
	DATABASES = {
    	'default': {
    	    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    	    'NAME': 'talk',
    	    'USER': 'postgres',
    	    'PASSWORD': DATABASE_PASSWORD,
    	    'HOST': '127.0.0.1',
    	    'PORT': '5432',
    	}
	}

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR + STATIC_URL
STATIC_DICT = {
    'chat': BASE_DIR + '/chat/static',
}

MEDIA_URL = '/media/'
MEDIA_DICT = {
    'document_root': BASE_DIR + MEDIA_URL,
}
if hostname in ('laptop', 'fedora.local', 'fedora-2.local', 'localhost.localdomain'):
    MEDIA_ROOT = BASE_DIR + MEDIA_URL
else :
    MEDIA_ROOT = '/opt/dmessage' + MEDIA_URL

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'debug': DEBUG, 
            'context_processors': [
                 'django.contrib.auth.context_processors.auth',
            ]
        },
    },
]

